package mlz.c_constructor;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ConstructorDemo02 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        //1.获取类的字节码对象
        Class<Person> person = Person.class;

        //2.获取类的构造方法
        Constructor<Person> c = person.getDeclaredConstructor();

        //3.设置访问权限
        c.setAccessible(true); //进制访问
        Person p = c.newInstance();

        p.setAge(21);

        int age = p.getAge();
        System.out.println(age);


        //原始获取的方式
        //new Person("张三", 18)


    }
}
